package com.sciencep.pro.common.domain;

import com.sciencep.pro.common.config.DictionaryConstant;
import io.swagger.annotations.ApiModel;
import lombok.Data;

import static com.sciencep.pro.common.config.Constant.ErrorCode.SUCCESS;
import static com.sciencep.pro.common.config.Constant.ErrorCode.SYSTEM_ERROR;

@ApiModel("统一返回类")
@Data
public class ResponseResult<T> {

    private static final String ERROR_CODE = "errorCode";

    private Boolean success;
    private String message;
    private String stateCode;
    private T data;


    public ResponseResult<T> success() {
        this.success = true;
        this.stateCode = SUCCESS;
        this.message = DictionaryConstant.getInstance().getDic(ERROR_CODE).get(SUCCESS);

        return this;
    }

    public ResponseResult<T> success(T data) {
        this.success = true;
        this.stateCode = SUCCESS;
        this.message = DictionaryConstant.getInstance().getDic(ERROR_CODE).get(SUCCESS);
        this.data = data;
        return this;
    }

    public ResponseResult<T> failure() {
        this.success = false;
        this.stateCode = SYSTEM_ERROR;
        this.message = DictionaryConstant.getInstance().getDic(ERROR_CODE).get(SYSTEM_ERROR);
        return this;
    }

    public ResponseResult<T> failure(String stageCode) {
        this.success = false;
        this.stateCode = stageCode;
        this.message = DictionaryConstant.getInstance().getDic(ERROR_CODE).get(SYSTEM_ERROR);
        return this;
    }

    public ResponseResult<T> failure(String stageCode, String message) {
        this.success = false;
        this.message = message;
        this.stateCode = stageCode;
        return this;
    }

    public ResponseResult<T> failure(String stageCode, String message, T date) {
        this.success = false;
        this.message = message;
        this.stateCode = stageCode;
        this.data = date;
        return this;
    }

    public T getData() {
        return data;
    }

}
